package utils;

import java.text.DecimalFormat;

public class Date extends java.sql.Date
{
	private static final long	serialVersionUID	= -811777808626696520L;

	private Integer day;
	private Integer month;
	private Integer year;
	
	@SuppressWarnings("deprecation")
	public Date( int day, int month, int year )
	{
		super( year - 1900, month - 1, day );
		
		this.day = day;
		this.month = month;
		this.year = year;
	}
	
	public Date( long date )
	{
		super( date );
		this.day = Integer.parseInt( String.format( "%td", this ) );
		this.month = Integer.parseInt( String.format( "%tm", this ) );
		this.year = Integer.parseInt( String.format( "%tY", this ) );
	}
	
	public int getDay()
	{
		return this.day;
	}
	
	public int getMonth()
	{
		return this.month;
	}
	
	public int getYear()
	{
		return this.year;
	}
	
	public boolean afterMonthDay( Date date )
	{
		boolean ret;
		
		ret = !( this.getMonth() < date.getMonth() );
		ret = !( this.getMonth() == date.getMonth() && this.getDay() < date.getDay() ) && ret;
		
		return ret;
	}
	
	public boolean betweenMonthDay( Date startDate, Date endDate )
	{
		boolean ret;
		
		ret = true;
		ret = ret && !( this.getMonth() < startDate.getMonth() );
		ret = ret && !( this.getMonth() > endDate.getMonth() );
		ret = ret && !( this.getMonth() == startDate.getMonth() && this.getDay() < startDate.getDay() );
		ret = ret && !( this.getMonth() == endDate.getMonth() && this.getDay() > endDate.getDay() );
		
		return ret;
	}
	
	public String toString()
	{
		String ret;
		
		DecimalFormat twoDigits = new DecimalFormat("00");
		DecimalFormat fourDigits = new DecimalFormat("0000");
		
		ret = String.format( "%s/%s/%s", twoDigits.format( day ), twoDigits.format( month ), fourDigits.format( year ) );
		
		return ret;
	}
	
	public static long getTime( int day, int month, int year )
	{
		long ret;
		
		Date date = new Date( day, month, year );
		ret = date.getTime();
		
		return ret;
	}
}
